package com.kjtpay.design_pattern.builder;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.kjtpay.design_pattern.R;
import com.kjtpay.design_pattern.facade.FacadeActivity;

public class BuilderActivity extends AppCompatActivity {

    public static void launch(Context context) {
        if (null != context) {
            Intent intent = new Intent();
            intent.setClass(context, BuilderActivity.class);
            if (!(context instanceof Activity)) {
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            }
            context.startActivity(intent);
        }
    }

    TextView infoTextView;
    Person thinPerson, fatPerson;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_builder);
        setTitle("建造者模式");

        infoTextView = findViewById(R.id.textViewInfo);

        PersonDirector director = new PersonDirector();
        // 画瘦子
        PersonThinBuilder thinBuilder = new PersonThinBuilder();
        director.createPerson(thinBuilder);
        thinPerson = thinBuilder.getPerson();

        // 画胖子
        PersonFatBuilder fatBuilder = new PersonFatBuilder();
        director.createPerson(fatBuilder);
        fatPerson = fatBuilder.getPerson();
    }

    public void onThinClick(View view) {
        infoTextView.setText(thinPerson.show());
    }

    public void onFatClick(View view) {
        infoTextView.setText(fatPerson.show());
    }
}